<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="app" uri="http://www.wanrenhui.com"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@include file="/res/include/base-head.jsp"%>
<%@include file="/res/include/jquery-easyui.jsp"%>
<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/ad/adBase.js"></script>
</head>
<body>
<form id="data-form">
	<div class="form_item">
		<dl>
			<dt>选择广告位置：</dt>
			<dd>
				<select name="type">
					<c:forEach items="${list}" var="item">
						<option value="${item.code}">${item.name}</option>
					</c:forEach>
				</select>
			</dd>
		</dl>
		<dl>
			<dt>社区：</dt>
			<dd>
				<select name="communityId">
					<option value="">请选择</option>
					<c:forEach items="${cList}" var="item">
						<option value="${item.id}">${item.name}</option>
					</c:forEach>
				</select>
			</dd>
		</dl>
		<dl>
			<dt>排序：</dt>
			<dd>
				<input  type="text" id="oidx" name="oidx" value="1"/>
			</dd>
		</dl>
		<dl>
			<dt>广告图片：</dt>
			<dd>
				<ul class="product_imglist img_imglist">
						<li><a href="javascript:;" class="item" id="pic0" type="img" onclick="admin.adBase.addImg('pic0')">添加图片</a>
						</li>
				</ul>
			</dd>
		</dl>
		<dl>
			<dt>标题：</dt>
			<dd>
			<input  type="text"  name="title"/> 
			</dd>
		</dl>
		<dl>
			<dt>标题图片：</dt>
			<dd>
				<ul class="product_imglist img_imglist">
						<li><a href="javascript:;" class="item" id="titlePic0" type="title" onclick="admin.adBase.addImg('titlePic0')">添加图片</a>
						</li>
				</ul>
			</dd>
		</dl>
		<dl>
			<dt>广告超链接地址：</dt>
			<dd>
			<input  type="text"  name="href"/> 
			</dd>
		</dl>
		<dl>
			<dt>UI参数：</dt>
			<dd>
			   <select id="jsonData" name="jsonData"  style="padding: 5px;" >
					<option value="">请选择店铺</option>
					<c:forEach items="${mallShopVos}" var="item">
						<option value="${item.id}">${item.name}</option>
					</c:forEach>
				</select>
				
			</dd>
		</dl>
		<dl>
			<dt>UI路径：</dt>
			<dd>
			<input  type="text"  name="path" value="source://view/qshop/detail/main.ui" /> 
			</dd>
		</dl>
		<dl>
			<dt>备注：</dt>
			<dd>
			<input  type="text"  name="remark"/> 
			</dd>
		</dl>
		<dl>
			<dt>内容：</dt>
			<dd>
				<textarea class="txt grid-75" id="content" name="content" oninput="admin.adBase.netMsgChange('content',360)" onpropertychange="admin.communityNotice.netMsgChange('content',360)" rows="4" ></textarea>
			</dd>
		</dl>
		<dl>
			<dt>内容图片：</dt>
			<dd>
				<ul class="product_imglist img_imglist">
					<c:forEach begin="0" end="4" varStatus="i">
						<li><a href="javascript:;" class="item" id="contentImgPic${i.index}" type="content" onclick="admin.adBase.addImg('contentImgPic${i.index}')">添加图片</a>
						</li>
					</c:forEach>
				</ul>
			</dd>
		</dl>
		<p class="page_btn"><input type="button" id="saveBtn" value="保存" class="btn_blue" onclick="doSave();"/></p>
	</div>
</form>
<script type="text/javascript">
	//提交保存
	var isSave = false;
	function doSave() {
		var img = "";
		var titleImg = "";
		var contentImg = "";
		var imglist = $(".img_imglist img");
		if (imglist && imglist.length > 0) {
			imglist.each(function() {
				var parent=$(this).parent().parent();
				if(parent.attr("type")=="img"){
					if (img == "") {
						img += $(this).attr("src").replace(imgFilePath, "");
					} else {
						img += ";" + $(this).attr("src").replace(imgFilePath, "");
					}
				}else if(parent.attr("type")=="title"){
					if (titleImg == "") {
						titleImg += $(this).attr("src").replace(imgFilePath, "");
					} else {
						titleImg += ";" + $(this).attr("src").replace(imgFilePath, "");
					}
				}else if(parent.attr("type")=="content"){
					if (contentImg == "") {
						contentImg += $(this).attr("src").replace(imgFilePath, "");
					} else {
						contentImg += ";" + $(this).attr("src").replace(imgFilePath, "");
					}
				}
			});
		} else {
			top.showInfo('请上传产品图片');
			return;
		}
		var url = contextPath + '/ad/base/add';
		if (!$('#data-form').form('validate'))
			return;
		if (isSave) {
			return;
		}
		isSave = true;
		var data = $('#data-form').form('jsonObject');
		data.img = img;
		data.titleImg = titleImg;
		data.contentImg = contentImg;
		if(data.jsonData!="")
			data.jsonData = "{\"shopId\":\""+data.jsonData+"\"}";
		else
			data.path = '';
		$.post(url, data, function(result) {
			if (result.code == 1) {
				top.showInfo('保存成功');
				top.addTab("",'广告记录', contextPath+'/ad/base/list');
			} else {
				isSave = false;
				top.showInfo('保存失败:' + result.msg);
			}
		}, 'json');
	}
</script>
</body>
</html>
